/*
 * SASettingslistContainer.cpp
 *
 *  Created on: 2010-06-04
 *      Author: NONO
 */

// System includes
#include <bautils.h>                            // BaflUtils
#include <eikmenup.h>                           // CEikMenuPane
#include <SMSAssist_0xEB692DC8.rsg>

// User includes
#include "SAAppUi.h"
#include "SASettingslistView.h"
#include "SA.hrh"
#include "SASettingItemList.h"
#include "SASettings.h"

// Class includes
#include "SASettingslistContainer.h"


// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CSASettingslistContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
// ---------------------------------------------------------
// Constructor, destructor
// ---------------------------------------------------------
CSASettingslistContainer::CSASettingslistContainer(CSAAppUi& aAppUi,CSASettings& aSettings):
    CSABaseContainer(aAppUi),iSettings(aSettings)
{
}

void CSASettingslistContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
    ChangeComponentL(ESettingList);
    
    SetRect(aRect);
    ActivateL();
}
    
/** 
* Destructor.  Frees up memory for the settings list.
*/
CSASettingslistContainer::~CSASettingslistContainer()
{
    delete iSettingItemList;
}
    
/**
* Called by the framework in compound controls  
* @return The number of controls in this CSettingsListContainer
*/
TInt CSASettingslistContainer::CountComponentControls() const
{
    return 1; // return number of controls inside this container
}

/**
* Called by the framework in compound controls  
* @param The index of the control to return
* @return The control for aIndex
*/
CCoeControl* CSASettingslistContainer::ComponentControl(TInt aIndex) const
    {
    switch (aIndex)
        {
        case 0:
        {
            switch (iCurrentComponent)
            {
                case ESettingList:
                    return iSettingItemList;
                default:
                    return NULL;
            }

        }
        default:
            return NULL;
        }
    }
    
// ---------------------------------------------------------
// CSASettingslistContainer::HandleResourceChange()
// Called by framework when layout is changed.
// ---------------------------------------------------------
//
void CSASettingslistContainer::HandleResourceChange(TInt aType)
    {
    CCoeControl::HandleResourceChange(aType);

    #if defined(__SERIES60_28__) || defined(__SERIES60_3X__)

    // ADDED FOR SCALABLE UI SUPPORT
    // *****************************
    if ( aType==KEikDynamicLayoutVariantSwitch )
        {
        TRect rect;
        AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
        SetRect(rect);
        }
        
    switch (iCurrentComponent)
        {
        case ESettingList:
        {
            if(iSettingItemList)
                iSettingItemList->HandleResourceChange(aType);
            break;
        }
        default:
            break;
        }
        
    #endif
    }



/**
* Called by the framework whenever a key event occurs.  
* Passes the key event to the saved games list if it is not null, otherwise returns
* EKeyWasNotConsumed
* @param aKeyEvent the Key event which occured, e.g. select key pressed
* @param aType the type of Key event which occurred, e.g. key up, key down
* @return TKeyResponse EKeyWasNotConsumed if the key was not processed, EKeyWasConsumed if it was
*/
TKeyResponse CSASettingslistContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
    
    if(iCurrentComponent==ESettingList)
    {
        if (iSettingItemList)
            return iSettingItemList->OfferKeyEventL (aKeyEvent, aType);
        else
            return EKeyWasNotConsumed;
    }
        
    return EKeyWasNotConsumed;
}
    

void CSASettingslistContainer::ChangeViewMenuL(TInt aResourceId)
{
    CSABaseContainer::ChangeViewMenuL(TUid::Uid(ESASettingslistViewId), aResourceId);
}


/**
* Asks the setting list to change the currently selected item
*/
void CSASettingslistContainer::ChangeSelectedItemL()
{
    if(iCurrentComponent==ESettingList)
        if (iSettingItemList)
            iSettingItemList->ChangeSelectedItemL();
}

void CSASettingslistContainer::EditItemL(TInt aIndex)
{
}
    
// ---------------------------------------------------------
// PhoneSelectControl control creator
// ---------------------------------------------------------
void CSASettingslistContainer::CreatePhoneSelectControlL()
{
//    iPhoneSelectControl = CMbsPhoneSelectControl::NewL(Rect(), this, CMbsPhoneSelectControl::EMultiEditSingleSelFromPbk,iSettings.TransNos(),iPaAppUi.iAppPath,3);
//    iPhoneSelectControl->CompleteConstructL();
//    iPhoneSelectControl->SetMopParent(this);
}
// ---------------------------------------------------------
// Protection PhoneSelectControl control creator
// ---------------------------------------------------------
void CSASettingslistContainer::CreateProtectionPhoneSelectControlL()
{
//    iProtectionPhoneSelectControl = CMbsPhoneSelectControl::NewL(Rect(), this, CMbsPhoneSelectControl::EMultiEditSingleSelFromPbk,iSettings.NotifyNos(),iPaAppUi.iAppPath,3);
//    iProtectionPhoneSelectControl->CompleteConstructL();
//    iProtectionPhoneSelectControl->SetMopParent(this);
}
// ---------------------------------------------------------
// Protection sub setting list control creator
// ---------------------------------------------------------
void CSASettingslistContainer::CreateProtectionSettingListL()
{
//    iProtectionSettingItemList = new CPaSettingItemList (iSettings,*this);
//    iProtectionSettingItemList->SetMopParent(this);
//    iProtectionSettingItemList->ConstructFromResourceL(R_PA_PROTECTION_SETTINGSLIST_SETTING_ITEM_LIST);//R_PA_PROTECTION_SETTINGSLIST_SETTING_ITEM_LIST
//    iProtectionSettingItemList->ActivateL();
}
// ---------------------------------------------------------
// SettingList control creator
// ---------------------------------------------------------
void CSASettingslistContainer::CreateSettingListL()
{
    iSettingItemList = new CSASettingItemList (iSettings,*this);
    iSettingItemList->SetMopParent(this);
    iSettingItemList->ConstructFromResourceL(R_SA_SETTINGSLIST_SETTING_ITEM_LIST);
}


// ---------------------------------------------------------
// Change or create to a new component
// ---------------------------------------------------------
void CSASettingslistContainer::ChangeComponentL(CSASettingslistContainer::TComponentIndication aCurrentComponent,
                                           TBool aDeleteOld)
{
    if (aCurrentComponent == iCurrentComponent)
        return;

    // Hide or show (create) settinglist
    if (iSettingItemList)
    {
        iSettingItemList->MakeVisible(aCurrentComponent == ESettingList);
        iSettingItemList->SetFocus(aCurrentComponent == ESettingList);
        if(aCurrentComponent == ESettingList)
            ChangeViewMenuL(R_SA_SETTINGSLIST_MENUBAR);
    }
    else
    {
        if (aCurrentComponent == ESettingList)
        {
            CreateSettingListL();
            iSettingItemList->SetFocus(ETrue);
//            iSettingItemList->SetItemFocus(iPaAppUi.GetListIndex());
            ChangeViewMenuL(R_SA_SETTINGSLIST_MENUBAR);
        }
    }
    
    // Decide whether to delete old component, must be put after new control creation
    if (aDeleteOld)
    {
        switch (iCurrentComponent)
        {
            case ESettingList:
                if (iSettingItemList)
                {
                    delete iSettingItemList;
                    iSettingItemList = NULL;
                }
                break;
            default:
                break;
        }
    }

    iCurrentComponent = aCurrentComponent;
}

void CSASettingslistContainer::HandleCommandFromContainerL(TInt aCommand)
{
    // Commands for other compoments.
    switch ( aCommand )
    {
        case ESASettingslistCmdOpen:
        {
            if(iCurrentComponent==ESettingList)
            {
                ChangeSelectedItemL();  
            }
            break;
        }
        default:
        {
            iSAAppUi.SaveSettingsL();
            iSAAppUi.HandleCommandL(aCommand);
            break;
        }
    }

}
// --------------------------------------------------------------
// void CSASettingslistContainer::DynInitMenuPaneFromContainerL(TInt aResourceId, CEikMenuPane* aMenuPane)
//
// --------------------------------------------------------------
//
void CSASettingslistContainer::DynInitMenuPaneFromContainerL(TInt aResourceId, CEikMenuPane* aMenuPane)
{

}

//modify 2007-06-15
void CSASettingslistContainer::UpdatePhoneNumberSettingItem()
{
//    _LIT(COMMA,",");
//
//    CMbsPhoneListModel* temp = iSettings.TransNos();
//    TInt cnt = temp->CountOfPhoneListItem();
//    TBuf<128> str;
//
//    for(TInt i = 0; i < cnt; ++i)
//    {
//        TInt len = (*(temp->PhoneList()))[i]->iPhoneNumber.Length();
//        if(len > 0)
//        {
//            if(str.Length()+len<128)
//            {
//                str.Append((*(temp->PhoneList()))[i]->iPhoneNumber);
//            }
//            else
//            {
//                str.Append((*(temp->PhoneList()))[i]->iPhoneNumber.Left(128-str.Length()));
//                break;
//            }
//            if(cnt-i>1)
//                str.Append(COMMA);
//        }
//    }
//
//    iSettings.SetManagePhoneNumber(str);
}

//modify 2007-06-15
void CSASettingslistContainer::UpdateProtectionPhoneNumberSettingItem()
{
//    _LIT(COMMA,",");
//
//    CMbsPhoneListModel* temp = iSettings.NotifyNos();
//    TInt cnt = temp->CountOfPhoneListItem();
//    TBuf<128> str;
//
//    for(TInt i = 0; i < cnt; ++i)
//    {
//        TInt len = (*(temp->PhoneList()))[i]->iPhoneNumber.Length();
//        if(len > 0)
//        {
//            if(str.Length()+len<128)
//            {
//                str.Append((*(temp->PhoneList()))[i]->iPhoneNumber);
//            }
//            else
//            {
//                str.Append((*(temp->PhoneList()))[i]->iPhoneNumber.Left(128-str.Length()));
//                break;
//            }
//            if(cnt-i>1)
//                str.Append(COMMA);
//        }
//    }
//
//    iSettings.SetNotificationPhoneNumber(str);
}

// End of File  
